package com.sino.operation.util;

/**
 * @ClassName ResponseFieldUtil
 * @Description 在校验参数的时候，返回异常信息的字段应该全部为大写,便于统一
 * @Author 北陈
 * @Date 2021/10/1 20:35
 * @Version 1.0
 */
public class ResponseFieldUtil {

    public static String changeToStandardByValid(String fieldName){
        if (fieldName != null && fieldName != "") {
            char[] chars = fieldName.toCharArray();
            StringBuilder builder = new StringBuilder();
            int length = chars.length;
            for (int i = 0; i < length; i++) {
                int charValue = (int) chars[i];
                char aChar = chars[i];
                if (charValue >= 65 && charValue <= 90) {
                    if (!builder.toString().contains("_")){
                        builder.append("_");
                    }
                    builder.append(chars[i]);
                } else if (charValue >= 97 && charValue <= 122) {
                    charValue = charValue - 32;
                    char value=(char) (charValue);
                    builder.append(value);
                }else if (aChar!='_'){
                    builder.append(aChar);
                }
                if (aChar == '_' && i != 0) {
                    if (!builder.toString().contains("_")){
                        builder.append("_");
                    }
                }

            }
            return builder.toString();
        }
        return fieldName;
    }

}
